from appium import webdriver #（appium 的本质继承于selenium, 基于selenium添加了对移动端额支持）
from time import sleep
# 创建一个desired_caps的空字典用于存放app的初始化值
from appium.webdriver.common.mobileby import MobileBy as By


class App:

    def __init__(self, driver=None):
        if driver is None:
            self.driver = self.start_app()
        else:
            self.driver = driver


    # 定义设置capability,初始化一个driver
    def start_app(self):
        # 创建一个 webdriver 对象 -> driver
        # 初始化一些数据（Cabilities) -> 该数据用于 appium-server 跟手机端创建一个唯一的会话session
        desired_caps = {}
        desired_caps['platformName'] = 'Android'  # 平台名称
        desired_caps['deviceName'] = 'emulator-5554'  # 设备名称
        desired_caps['appPackage'] = 'com.xueqiu.android'  # 被测app包名
        desired_caps['appActivity'] = 'view.WelcomeActivityAlias'  # 被测app启动页
        # 初始化一个driver对象
        driver = webdriver.Remote('http://192.168.136.1:4723/wd/hub', desired_caps)
        driver.implicitly_wait(10)  # 隐式等待
        return driver
